//
//  EditPictureListTagView.m
//  jingdongfang
//
//  Created by RKL on 2018/5/21.
//  Copyright © 2018年 BOE-SBG-CTO. All rights reserved.
//

#import "EditPictureListTagView.h"

@implementation EditPictureListTagView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}
- (void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    
}

#pragma mark - 创建UI
- (void)reloadeData
{
    for (UIView * view in self.subviews)
    {
        [view removeFromSuperview];
    }
    
    float betweenWidth = 10;
    float btnMinX = self.width-15;

    for (int i = 0; i < self.dataArray.count; i++)
    {
        IGArtDetailLibrary * lib = self.dataArray[i];
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:lib.title forState:UIControlStateNormal];
        [btn setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
        [btn setBackgroundColor:RGB(0, 171, 230)];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        btn.layer.cornerRadius = 10;
        [btn sizeToFit];
        btn.frame = CGRectMake(btnMinX - (btn.width+20), 18, btn.width+20, 30);
        btn.tag = 1000+i;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        btnMinX = CGRectGetMinX(btn.frame) - betweenWidth;
        
        UIImageView * delegateImageView = [[UIImageView alloc] init];
        delegateImageView.image = [UIImage imageNamed:@"pic_delete"];
        delegateImageView.frame = CGRectMake(btn.width-10, -5, 15, 15);
        delegateImageView.userInteractionEnabled = YES;
        [btn addSubview:delegateImageView];
        
    }
}

- (void)btnClick:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(removeButtonTag:)])
    {
        [self.delegate removeButtonTag:sender.tag-1000];
    }
}
@end












